import {
  IsOptional,
  IsNumber,
  IsString,
  IsDateString,
  IsBoolean,
} from 'class-validator';
import { Type, Transform } from 'class-transformer';

/**
 * 基础 DTO 类
 * 基于 class-validator 实现
 * 对应 Java: BaseDTO
 */
export abstract class BaseDto {
  @IsOptional()
  @IsNumber()
  @Type(() => Number)
  id?: number;

  @IsOptional()
  @IsNumber()
  @Type(() => Number)
  siteId?: number;

  @IsOptional()
  @IsNumber()
  @Type(() => Number)
  createBy?: number;

  @IsOptional()
  @IsNumber()
  @Type(() => Number)
  updateBy?: number;

  @IsOptional()
  @IsDateString()
  createTime?: string;

  @IsOptional()
  @IsDateString()
  updateTime?: string;

  @IsOptional()
  @IsDateString()
  deleteTime?: string;

  @IsOptional()
  @IsNumber()
  @Type(() => Number)
  isDelete?: number;
}

/**
 * 分页查询 DTO
 */
export class PaginationDto {
  @IsOptional()
  @IsNumber()
  @Type(() => Number)
  @Transform(({ value }) => Math.max(1, parseInt(value) || 1))
  page?: number = 1;

  @IsOptional()
  @IsNumber()
  @Type(() => Number)
  @Transform(({ value }) => Math.min(100, Math.max(1, parseInt(value) || 10)))
  limit?: number = 10;

  @IsOptional()
  @IsString()
  keyword?: string;

  @IsOptional()
  @IsString()
  sortBy?: string;

  @IsOptional()
  @IsString()
  sortOrder?: 'ASC' | 'DESC' = 'DESC';
}

/**
 * ID 参数 DTO
 */
export class IdDto {
  @IsNumber()
  @Type(() => Number)
  id: number;
}

/**
 * 批量操作 DTO
 */
export class BatchDto {
  @IsNumber({}, { each: true })
  @Type(() => Number)
  ids: number[];
}
